<link rel="stylesheet" href="/ceca_two/css/costShareOne.css" />
<!--header-->
<!--# include virtual="/ceca_two/common/html/header.html"-->
<!--# include virtual="/ceca_two/modules/quota/base/guidanceShare.html"-->
<style type="text/css">
	input::-webkit-outer-spin-button,
	input::-webkit-inner-spin-button {
		-webkit-appearance: none;
	}
	
	input[type="number"] {
		-moz-appearance: textfield;
	}
	
	tr td:last-child {
		overflow: hidden;
	}
	
	tr td:last-child span {
		width: 230px;
		display: block;
		overflow: hidden;
		text-indent: 2em;
		text-overflow: ellipsis;
		line-height: 40px;
		max-height: 40px;
		white-space: nowrap;
	}
	
	.fill {
		border: 1px solid #ff3030!important;
	}
	
	select {
		width: 25%;
		height: 100%;
		display: block;
		border: none;
		box-sizing: border-box;
		text-indent: 20px;
		float: left;
	}
	
	.layer-anim {
		width: auto!important;
	}
	
	#fileBtn {}
	
	input[type=file] {
		display: none;
	}
</style>
<h1 class="shareName">信息价</h1>
<table class="shareTable">
	<tr>
		<td style="width: 10%"></td>
		<td class="property" style="width: 90%"></td>
	</tr>
	<tr>
		<td>发布地区</td>
		<td class="property proL" id="field">
			<select name="firstField" id="firstField"></select>
			<select name="secondField" id="secondField" style="display: none;"></select>
			<select name="thirdField" id="thirdField" style="display: none;"></select>
			<select name="fourthField" id="fourthField" style="display: none;"></select>
		</td>
	</tr>
	<tr>
		<td>发布年月</td>
		<td class="property">
			<div class="layui-input-block" style="margin-left: 10px">
				<input class="layui-input" onclick="layui.laydate({elem: this, format:'YYYY-MM'})" placeholder="选择年月" style="border: none;cursor: pointer;" name="time" id="time">
			</div>
		</td>
	</tr>
	<tr>
		<td>信息价名称</td>
		<td class="property">
			<input type="text" id="guidanceName" name="guidanceName" value="" placeholder="请输入信息价名称" />
		</td>
	</tr>
	<tr>
		<td>专业</td>
		<td class="property">
			<select name="major" id="major">
				<option value="建设工程">建设工程</option>
				<option value="公路工程">公路工程</option>
				<option value="铁路工程">铁路工程</option>
				<option value="电力工程">电力工程</option>
				<option value="其他">其他</option>
			</select>
		</td>
	</tr>
	<tr>
		<td>信息价文件</td>
		<td class="property">
			<strong id="fileBtn" href="javascript:;">请上传信息价文件</strong><input id="file_url" name="file_url"  style="display: none;"></input>
		</td>
	</tr>
	<tr>
		<td>本期说明</td>
		<script id="explains" name="explains" type="text/plain" style="width:100%;height:800px;text-align: left;background: #fff!important;"></script>
	</tr>
</table>
<div class="shareCostBtn">
	<div class="saveBtn" style="margin: 50px 20px 50px 477px;">
		<a onclick="history.go(-1);" href="javascript:;">返回</a>
	</div>
	<div class="nextBtn" style="cursor: pointer;">
		<a id="submit">提交</a>
	</div>
</div>
</div>
</div>
<div id="tip" style="width: 1240px;padding: 0 0 20px;color: red;text-align: center;background: #fff;display: none;margin: 0 auto;"></div>
<!--底部-->
<!--# include virtual="/ceca_two/common/html/footer.html"-->
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/ueditor.all.js"></script>
<script type="text/javascript" src="/ceca_two/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/ceca_two/js/costnorm/webuploader.js"></script>
<script type="text/javascript">
	$(function() {
		var fileSchedule = true;
		var uploaderFile = WebUploader.create({
			auto: true, // 选完文件后，是否自动上传。
			swf: '/ceca_two/js/costnorm/Uploader.swf',
			server: '/admin/lib/ueditor/1.4.3/jsp/controller.jsp?action=uploadfile&encode=utf-8', // 文件接收服务端。
			pick: '#fileBtn',
			resize: false,
			duplicate: true,
			accept: { // 只允许选择excel表格文件。
				title: 'Applications',
				extensions: 'rar,zip,excel,pdf',
				mimeTypes: 'application/rar'
			}
		});
		uploaderFile.on('uploadSuccess', function(file, response) {
			$("#fileBtn").html(response.original)
			$("#file_url").val(response.url)
		});
		// 文件上传失败，显示上传出错。
		uploaderFile.on('uploadError', function(file, reason) {
			alert("文件上传失败")
		});
	});
</script>
<script>
	layui.use(['laydate', 'sharecity', 'layer'], function() {
		var dataList = [];
		var firstData ={code:null,name:null};
		var secondData ={code:null,name:null}; 
		var thirdData = {code:null,name:null};
		var childList = [];
		var child_childList = [];
		var child_child_childList = [];
		$.getJSON("/ceca_two/router/area.json", function(data) {
			dataList = data
			var html = "";
			dataList.forEach(function(item) {
				html += "<option value=" + item.code + " >" + item.name + "</option>";
			})
			if(html != "") $("#firstField").show().html("<option value=''>请选择</option>" + html);
		});
		$("#firstField").change(function() {
			if(this.value == "") {
				$("#secondField").hide().empty()
				$("#thirdField").hide().empty()
				$("#fourthField").hide().empty()
			} else {
				var code = this.value
				var html = "";
				firstData = dataList.find(function(item) {
					return item.code == code
				})
				childList = firstData.child || []
				childList.forEach(function(item) {
					html += "<option value=" + item.code + " >" + item.name + "</option>";
				})
				if(html != "") {
					$("#secondField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#secondField").hide().empty()
					$("#thirdField").hide().empty()
					$("#fourthField").hide().empty()
				}
			}
		});

		$("#secondField").change(function() {
			if(this.value == "") {
				$("#thirdField").hide().empty()
				$("#fourthField").hide().empty()
			} else {
				var code = this.value
				var html = "";
				secondData = childList.find(function(item) {
					return item.code == code
				})
				child_childList = secondData.child || []
				child_childList.forEach(function(item) {
					html += "<option value=" + item.code + " >" + item.name + "</option>";
				})
				if(html != "") {
					$("#thirdField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#thirdField").hide().empty()
					$("#fourthField").hide().empty()
				}
			}
		});
		$("#thirdField").change(function() {
			if(this.value == "") {
				$("#fourthField").hide().empty()
			} else {
				var code = this.value
				var html = "";
				thirdData = child_childList.find(function(item) {
					return item.code == code
				})
				child_child_childList = thirdData.child || []
				child_child_childList.forEach(function(item) {
					html += "<option value=" + item.code + " >" + item.name + "</option>";
				})
				if(html != "") {
					$("#fourthField").show().html("<option value=''>请选择</option>" + html);
				} else {
					$("#fourthField").hide().empty()
				}
			}
		});
		UE.getEditor('explains');
		$("#submit").click(function() {
			console.dir(thirdData)
			console.dir(secondData)
			console.dir(firstData)
			var areaCode = thirdData.code ? thirdData.code : (secondData.code ? secondData.code : (firstData.code ? firstData.code : ""))
			if(!areaCode || areaCode.length == 0) {
				$("#tip").show().html("请选择发布地区");
				return false;
			}
			var province =firstData.name
			var city = secondData.name
			var county = thirdData.name
			var time = $("#time").val();
			
			if(!time || time.length == 0) {
				$("#tip").show().html("请选择发布年月");
				return false;
			}
			
			var year = time.split("-")[0];
			var month = time.split("-")[1];
			var guidanceName = $("#guidanceName").val();
			if(!guidanceName || guidanceName.length == 0) {
				$("#tip").show().html("请填写信息价名称");
				return false;
			}
			var file_url = $("#file_url").val();
			if(!file_url || file_url.length == 0) {
				$("#tip").show().html("请上传信息价文件");
				return false;
			}
			
			var major = $("#major").val();
			var explains = UE.getEditor('explains').getContent()
			if(!explains || explains.length == 0) {
				$("#tip").show().html("请填写本期说明");
				return false;
			}
			var obj = {
				"areaCode": areaCode,
				"province": province,
				"city": city,
				"county": county,
				"year": year,
				"month": month,
				"guidanceName": guidanceName,
				"major": major,
				"explains": explains,
				"file_url":file_url
			}
			$.post("/guidance_service/front/me/share/guidance/add.do", obj, function(data) {
				if(data.resultCode ==200){
					alert(data.message)
					window.location.href="/ceca_two/modules/share/index.html";
				}else{
					alert(data.message)
				}
			});
		});
	});
</script>
</body>

</html>